package com.zp.base.admin.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.zp.base.admin.common.annotation.AddGroup;
import com.zp.base.admin.common.annotation.UpdateGroup;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

/**
 * 
 * 
 * @author zhangpeng
 * @email zhangpeng@aliyun.com
 * @date 2021-02-28 11:15:56
 */
@Data
@TableName("zp_user")
public class UserEntity implements Serializable, UserDetails {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	@NotNull(message = "修改时用户ID不能为空", groups = {UpdateGroup.class})
	@Null(message = "添加时用户ID为空", groups = {AddGroup.class})
	private Long id;
	/**
	 * 
	 */
	private Date createTime;
	/**
	 * 
	 */
	private Date updateTime;
	/**
	 * 
	 */
	private String email;
	/**
	 * 
	 */
	private String headPic;
	/**
	 * 
	 */
	private String mobile;
	/**
	 * 
	 */
	@NotEmpty(message = "密码不能为空", groups = {AddGroup.class})
	private String password;
	/**
	 * 
	 */
	private Integer sex;
	/**
	 * 
	 */
	private Integer status;
	/**
	 * 
	 */
	@NotEmpty(message = "用户名不能为空", groups = {AddGroup.class, UpdateGroup.class})
	private String username;

	@TableField(exist = false)
	private List<GrantedAuthority> authorities = new ArrayList<>();

	@Override
	public List<GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return this.status == 1 ? true : false;
	}
}
